<template>
  <div :class="typeInfo.class ? 'special_input '+ typeInfo.class : 'special_input'">


    <template v-if="typeInfo.type=='search'">
      <el-input type="txt" class="search" :maxlength="typeInfo.maxlength" v-model="data" clearable :placeholder="typeInfo.placeholder">
        <i slot="suffix" class="el-input__icon el-icon-search" style="color:#448afc" @click="forwards(typeInfo.fun,data)"></i>
      </el-input>
    </template>
    <template v-else-if="typeInfo.type=='text_area'">
      <div class="textarea_box" ref="text_box">
        <el-input v-if="typeInfo.focus" type="textarea" :maxlength="typeInfo.maxlength" :clearable="typeInfo.clearable"
          :disabled="typeInfo.disabled" :placeholder="typeInfo.placeholder" v-model="data"  resize="none" debounce
          v-focus>
        </el-input>
        <el-input v-else type="textarea" :maxlength="typeInfo.maxlength" :clearable="typeInfo.clearable"
          :disabled="typeInfo.disabled" :placeholder="typeInfo.placeholder" v-model="data" debounce  resize="none">
        </el-input>
        <div class="count" v-if="typeInfo.maxlength">{{data.length}}/{{typeInfo.maxlength}}</div>
      </div>
    </template>
    <template v-else-if="typeInfo.type=='timers'">
      <el-date-picker style="width:100%;" v-model="data" type="daterange" value-format="yyyy-MM-dd"
        start-placeholder="开始日期" end-placeholder="结束日期" prefix-icon="timer-color el-icon-date" >
        <i slot="suffix" class="el-input__icon el-icon-search" style="color:#448afc"></i>
      </el-date-picker>
    </template>

    <template v-else-if="typeInfo.type=='veri_code'">
      <div class="veri_code">
       
        <el-input class="fl veri_input" v-model="data" placeholder="请输入验证码" >
        </el-input>
       

        <div class="btn_area">
          
          <div class="code_btn fl" @click="typeInfo.fun" v-if="typeInfo.veri_time==0">发送验证码</div>
          <div class="code_btn fl count_down" v-if="typeInfo.veri_time!==0">{{typeInfo.veri_time}} 秒</div>
        </div>

        <div class="clear"></div>

      </div>
    </template>


    <template v-else-if="typeInfo.type=='up_down_ground'">
      <div class="up_down_ground">
        <el-input placeholder="请输入内容" v-model="data" :class="typeInfo.imp==true?'imp':''" :disabled="typeInfo.disabled">
          <div slot="prefix" class="up_down_ground_i">
            <span class="con" v-if="typeInfo.imp==true">
              <span class="star">*</span>
              {{typeInfo.con}}
            </span>
            <span class="con" v-else>
              {{typeInfo.con}}
            </span>
          </div>
        </el-input>
      </div>
    </template>
  </div>
</template>
<script>
  import specialRules from '@/assets/js/specialVerification'
  export default {
    name: 'special_input',
    data() {
      return {
        specialRules: specialRules,
        input_info: {
          type: ''
        },
        data: this.dataInput
      }
    },
    watch: {
      data: {
        handler: function (val) {
          this.$emit('parent-event', val);
        },
        deep: true
      },
      dataInput: {
        handler: function (val) {
          if (this.$refs.text_box) {
            let o = this.$refs.text_box.querySelector('textarea');
            o.scrollTop = o.scrollHeight
          }

          this.data = val;
        },
        deep: true
      }
    },
    methods:{
      forwards(fun, scope) {
        fun(scope)
      }
    },
    directives: {
      focus: {
        inserted: function (el) {
          el.querySelector('textarea').focus()
        }
      }
    },
    model: {
      prop: 'dataInput',
      event: 'parent-event'
    },
    props: ['typeInfo', 'dataInput', 'codeModel']
  }
  // 验证码 veri_code
  // 地上地下 up_down_ground
  // 搜索  search
  // 时间  timers 
  // 文本框  textarea :show-password=""
  // text

</script>
<style>
/* 搜索 */
.search.el-input--suffix:hover .el-input__inner{
  padding-right:50px;
}
.search.el-input--suffix .el-input__inner:focus {
  padding-right:50px;
}
.special_input{line-height: 0;}
  /* veri_code */

  .veri_code {
    /* margin-bottom: 15px; */
    padding-right: 140px;
    position: relative;
  }

  .veri_code .veri_input {
    height: 40px;
  }

  .veri_code .btn_area .code_btn {
    width: 120px;
    height: 40px;
    background: #458afb;
    border-radius: 4px;
    box-sizing: border-box;
    line-height: 40px;
    text-align: center;
    color: #fff;
    cursor: pointer;
  }


  .veri_code .btn_area {
    position: absolute;
    right: 0;
    top: 0;
  }

  .veri_code.count_down {
    background: #c6d2e6;
  }

  /* 地上地下 */
  .special_input .up_down_ground .up_down_ground_i {
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    width: 50px;
    color: #1b1b1b;
  }

  .special_input .up_down_ground .up_down_ground_i .con {
    width: 100%;
    height: 20px;
    padding-right: 10px;
    border-right: 1px solid #dcdcdc;
  }

  .special_input .up_down_ground .el-input__inner {
    padding-left: 60px;
  }

  .special_input .up_down_ground .imp .el-input__inner {
    padding-left: 70px;
  }

  .special_input .up_down_ground .imp .up_down_ground_i {
    width: 60px;
  }

  /* 文本域 */
  .el-textarea .el-input__count{
    bottom:16px;
  }
  .el-textarea .el-textarea__inner{
    overflow: auto;
  }
   .textarea_box {
    position: relative;
  }

  .textarea_box .el-textarea__inner {
    padding-bottom: 30px;
  }

  .textarea_box .count {
    width: 100%;
    height: 30px;
    line-height: 30px;
    text-align: right;
    position: absolute;
    right: 20px;
    left: 2px;
    box-sizing: border-box;
    bottom: 1px;
    background: #fff;
  } 

  /* 搜索框 */
  /* .special_input_30 .el-input__icon{line-height:30px;} */
  /* 输入框 */

  /* .special_input_30 .el-input__inner {
    height: 30px;
    font-size: 12px;
    line-height: 30px;
    padding-left: 60px;
    color: #1b1b1b;
  }

  .special_input_30 .input__inner {
    padding-left: 70px;
  } */
  .special_input .timer-color {

    color: #dcdcdc !important;
  }

</style>
